/*
 * @Title: 拼团优惠券  --  后台说先不做
 * @Author: JSL
 * @Date:   2018-10-25
 * @Last Modified by:   JSL
 * @Last Modified time: 2018-11-23
 */
var dataInfo = {},
  template = {
    init: function() {
      dataInfo.init = new Vue({
        el: '#app',
        data: {
          tabData: [{
            name: '未使用',
          }, {
            name: '已使用',
          }, {
            name: '已失效',
          }, ],
          listData: [],
          active: 0,
          loading: false,
          isLoading: false,
          finished: false,
          listLength: 1,
          page: 1,
          showNum: 0, //控制无数据小人
          limit: 10
        },
        methods: {
          onLoad: function() {
            this.listLength > this.listData.length ? this.getList() : '';
            this.loading = false;
            this.isLoading = false;
          },
          onRefresh: function() { //下拉刷新
            this.page = 1;
            this.listData = [];
            dataInfo.init.getList();
            setTimeout(function() {
              dataInfo.init.loading = false;
              dataInfo.init.isLoading = false;
            }, 500);
          },
          toUse: function(item) { //未使用 - 去使用
            //优惠券共三种情况
            //1.商品 - 跳转单独商品详情
            //2.拼团 - 跳转团长拼团
            //3.全场通用 - 不包括拼团
            if (item.type == 4) {
              location.href = 'PtIndex.html?GroupType=colonel_free_pt_groupon';
            } else if (item.scope == 2) { //特定商品优惠券
              location.href = 'productDetails.html?isFx=1&productId=' + item.virtualGoodsCode;
            } else { //item.scope==1 订单级 所有普通商品列表
              location.href = 'index.html';
            };
          },
          getList: function() {
            ajaxTemplate(addressUrl + SERVICE.queryUserCouponsV2, function(data) {
              console.log(data);
              if (data.tag == 0) {
                dataInfo.init.listLength = data.data.total;
                dataInfo.init.listData = dataInfo.init.listData.concat(data.data.result);
                dataInfo.init.showNum = dataInfo.init.listData.length;
                console.log(dataInfo.init.listData);
              } else {
                dataInfo.init.$toast(data.errMsg);
              };
            }, {
              userId: userId,
              type: this.active,
              limit: this.limit,
              page: this.page++,
              couponsType: 4 //优惠券类型，4-团长免单券，2-满减优惠券
            });
          },
        },
        watch: {
          active: function(e) {
            this.page = 1;
            this.showNum = 1;
            this.listData = [];
            document.body.scrollTop = 0;
            document.documentElement.scrollTop = 0;
            dataInfo.init.getList();
          }
        }
      });
      //初始化函数

    },
  };
template.init();
